package cn.stylefeng.guns.modular.cb.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.cb.entity.CbResume;
import cn.stylefeng.guns.modular.cb.mapper.CbResumeMapper;
import cn.stylefeng.guns.modular.cb.model.params.CbResumeParam;
import cn.stylefeng.guns.modular.cb.model.result.CbResumeResult;
import  cn.stylefeng.guns.modular.cb.service.CbResumeService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  简历 服务实现类
 * </p>
 *
 * @author wj
 * @since 2021-01-06
 */
@Service
public class CbResumeServiceImpl extends ServiceImpl<CbResumeMapper, CbResume> implements CbResumeService {

    @Override
    public void add(CbResumeParam param){
        CbResume entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(CbResumeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(CbResumeParam param){
        CbResume oldEntity = getOldEntity(param);
        CbResume newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public CbResumeResult findBySpec(CbResumeParam param){
        return null;
    }

    @Override
    public List<CbResumeResult> findListBySpec(CbResumeParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(CbResumeParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 每日新增简历统计
     * @param startDate
     * @param countArr
     * @return
     */
    @Override
    public List<Map<String, Object>> queryDateCount(String startDate, String[] countArr) {
        return this.baseMapper.queryDateCount(startDate, countArr);
    }

    private Serializable getKey(CbResumeParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private CbResume getOldEntity(CbResumeParam param) {
        return this.getById(getKey(param));
    }

    private CbResume getEntity(CbResumeParam param) {
        CbResume entity = new CbResume();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
